Skip to content

perf: precompute org page contributors leaderboard - #4501

Merged
epipav merged 2 commits into
mainfrom
perf/org-page-contributors-precompute
Aug 25, 2026
Merged

perf: precompute org page contributors leaderboard#4501
epipav merged 2 commits into
mainfrom
perf/org-page-contributors-precompute

Conversation

@epipav

@epipav epipav commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Optimizes org_page_contributors endpoint pipe with a nightly dedicated precompute copy pipe

Signed-off-by: anilb <epipav@gmail.com>
Copilot AI balanced review requested due to automatic review settings August 24, 2026 07:15
@cursor

cursor Bot commented Aug 24, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
All-time leaderboard results can lag until the nightly rebuild; date-range queries still use the live scan, so behavior splits on parameters.

Overview
Speeds up the dominant org contributors leaderboard path by avoiding a per-request scan of the ~744M-row activityRelations union when no date range is passed.

Adds org_page_contributors_copy_ds (per-organizationId / memberId all-time counts) and org_page_contributors_copy_pipe, which rebuilds that table nightly via COPY_MODE replace (schedule 50 3 * * *). org_page_contributors.pipe now sets use_precomputed unless startDate or endDate is set, and uses the copy datasource for count and aggregate nodes in that case; date-filtered requests still aggregate from activityRelations_deduplicated_cleaned_bucket_union unchanged.

Reviewed by Cursor Bugbot for commit 56d7404. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@epipav
epipav requested review from gaspergrom and removed request for Copilot August 24, 2026 07:16
@epipav epipav self-assigned this Aug 24, 2026
Comment thread services/libs/tinybird/pipes/org_page_contributors_copy_pipe.pipe
Copilot AI balanced review requested due to automatic review settings August 25, 2026 08:44
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@epipav
epipav merged commit 5f8c831 into main Aug 25, 2026
14 of 15 checks passed
@epipav
epipav deleted the perf/org-page-contributors-precompute branch August 25, 2026 08:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Precomputes organization contributor leaderboards nightly to reduce expensive request-time scans.

Changes:

  • Adds a precomputed contributor-count datasource and scheduled copy pipe.
  • Uses precomputed data for unfiltered requests while retaining date-filtered scans.
  • Note: the PR title lacks the required (CM-XXX) suffix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
org_page_contributors.pipe Routes unfiltered queries to precomputed data.
org_page_contributors_copy_pipe.pipe Builds the nightly contributor snapshot.
org_page_contributors_copy_ds.datasource Stores per-organization contributor counts.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +25 to +28
{% if use_precomputed == 1 %}
SELECT count()
FROM org_page_contributors_copy_ds
WHERE organizationId = (SELECT id FROM org_slug_lookup)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 56d7404. Configure here.

SELECT organizationId, memberId, count() AS contributionCount, now() AS computedAt
FROM activityRelations_deduplicated_cleaned_bucket_union
WHERE organizationId != ''
GROUP BY organizationId, memberId

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contributors include stars and forks

High Severity

The new COPY aggregates every activity row per (organizationId, memberId) with no activityTypes / code-contribution filter. Stargazers, forkers, and similar engagement actors become “contributors,” which can inflate leaderboard counts by an order of magnitude. Sibling org-page COPY pipes (org_page_kpis, org_page_contributors_timeseries, org_page_projects) already restrict to code contributions.

Fix in Cursor Fix in Web

Triggered by learned rule: Tinybird pipes counting contributors must filter by activityTypes

Reviewed by Cursor Bugbot for commit 56d7404. Configure here.

SELECT organizationId, memberId, count() AS contributionCount, now() AS computedAt
FROM activityRelations_deduplicated_cleaned_bucket_union
WHERE organizationId != ''
GROUP BY organizationId, memberId

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty memberId counted as contributor

Medium Severity

The COPY filters organizationId != '' but not memberId != '', so unresolved/empty member IDs become one row per org. The new precomputed count() paths then count that row as a real contributor, while the leaderboard INNER JOIN to members_sorted drops it—so count mode and the listed leaderboard disagree by one.

Additional Locations (2)
Fix in Cursor Fix in Web

Triggered by learned rule: Tinybird pipes with count(DISTINCT memberId/organizationId) must filter empty string values

Reviewed by Cursor Bugbot for commit 56d7404. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants